package component;

import com.fasterxml.jackson.core.JsonProcessingException;
import dao.EmployerDao;
import listener.ActionDoneListener;
import utils.ScreenUtils;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.Vector;

public class FindByMarriageDialog extends JDialog {
    final int WIDTH = 400;
    final int HEIGHT = 360;
    private EmployerDao employerDao = new EmployerDao();
    private ActionDoneListener listener;
    public static String MARRIAGE ;


    private JTable table;
    private Vector<String> titles;
    private Vector<Vector> tableData;
    private DefaultTableModel tableModel;
    public FindByMarriageDialog(JFrame jf, String title, boolean isModel, ActionDoneListener listener){
        super(jf,title,isModel);
        this.listener  = listener;
        //组装视图
        this.setBounds((ScreenUtils.getScreenWidth()-WIDTH)/2,(ScreenUtils.getScreenHeight()-HEIGHT)/2,WIDTH,HEIGHT);

        Box vBox = Box.createVerticalBox();


        //组装学历
        Box degreeBox = Box.createHorizontalBox();
        JLabel degreeLabel = new JLabel("婚姻状况：");
        JRadioButton marriageBtn = new JRadioButton("已婚",true);
        JRadioButton singleBtn = new JRadioButton("未婚",false);
        //实现单选的效果
        ButtonGroup bg2 = new ButtonGroup();
        bg2.add(marriageBtn);
        bg2.add(singleBtn);



        degreeBox.add(degreeLabel);
        degreeBox.add(Box.createHorizontalStrut(20));
        degreeBox.add(marriageBtn);
        degreeBox.add(singleBtn);
        degreeBox.add(Box.createHorizontalStrut(120));





        //组装按钮
        Box btnBox = Box.createHorizontalBox();
        JButton addBtn = new JButton("查询");
        addBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //获取用户的录入
                MARRIAGE = bg2.isSelected(marriageBtn.getModel()) ? marriageBtn.getText():singleBtn.getText();
                dispose();
                try {
                    listener.done(null);
                } catch (JsonProcessingException ex) {
                    ex.printStackTrace();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        });


        btnBox.add(addBtn);


        vBox.add(Box.createVerticalStrut(15));
        vBox.add(degreeBox);
        vBox.add(Box.createVerticalStrut(15));
        vBox.add(btnBox);

        //为了左右有间距，在vBox外层封装一个水平的Box，添加间隔
        Box hBox = Box.createHorizontalBox();
        hBox.add(Box.createHorizontalStrut(20));
        hBox.add(vBox);
        hBox.add(Box.createHorizontalStrut(20));

        this.add(hBox);

    }



}
